 <template>
 	<view :class="isHasDataFlag && (payStatus == -1 || payStatus == 0) ? 'hasPaddBot' : ''">
		<tab :orderStaIndex="orderStaIndex" :orderStaArr="orderStaArr" @switchStatus="switchStatus"/>
		<block v-if="isHasDataFlag">
			<order-list
				:orderList="orderList" 
				:loading="loading"
				currPageType="zxTcOrder"
				@goOrderDet="goOrderDet"
				@goPay="goPay"
				@cancelOrder="cancelOrder"
				@againBuyZxTc="againBuyZxTc"
			>
			</order-list>
			<order-tips v-if="payStatus == -1 || payStatus == 0"></order-tips>
		</block>
		<block v-else-if="isHasDataFlag == false">
			<no-data></no-data>
		</block>
		<common-alert :showAlertFlag="showAlertFlag" :alertWidth="alertWidth">
			<view class="alertContent">{{alertCon}}</view>
			<view class="tui-alert-btn" :hover-stay-time="150">
				<view class="cancelBtn" @tap.stop="cancelDel">取消</view>
				<button :disabled="isDisOrderFlag" class="sureBtn" @tap="sureFun">{{sureBtnTit}}</button>
			</view>
		</common-alert>
 	</view>
 </template>
 
 <script>
	import Tab from '../zxOrder/components/Tab';
	import OrderList from '../zxOrder/components/OrderList';
	import { getZxTcOrderList,cancelZxTcOrder } from '@/api/xlzx/index'
	import zxTcMixsin from '../../subIndex/zxsDet/mixins/zxTcMixsin';
 	export default {
		components:{
			Tab,
			OrderList
		},
		mixins:[zxTcMixsin],
		data(){
			return{
				orderStaArr:[
					{id:'-1',name:'全部'},
					{id:'0',name:'待支付'},
					{id:'1',name:'已完成'},
					{id:'7',name:'已取消'}
				],
				orderStaIndex:0,
				nowPage:1,
				payStatus:-1,
				loading:false,
				isHasDataFlag:null,
				orderList:[],
				isRefreshFlag:false,
				showAlertFlag:false,
				maskClosable:true,
				alertWidth:600,
				currOrderId:'',
				isDisOrderFlag:false,
				currTcId:0,
				confirmOpt:'',
				alertCon:'',
				sureBtnTit:'确认'
			}
		},
 		onLoad(){
			this.loadTcList();
		},
		onShow(){
			if(this.isRefreshFlag || this.againOrderFlag){
				this.initParams();
			}
		},
		onHide(){
			this.againOrderFlag = false;
			this.isRefreshFlag = false;
		},
		onUnload(){
			uni.removeStorageSync('zxTcInfoField');
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading ){
				this.loadTcList();
			}
		},
		methods:{
			cancelOrder(orderId){
				this.showAlertFlag = true;
				this.currOrderId = orderId;
				this.confirmOpt = 'cancel';
				this.alertCon = '是否确认取消该咨询套餐订单?';
			},
			cancelDel(){
				this.showAlertFlag = false;
				this.confirmOpt = '';
				this.alertCon = '';
				this.isDisOrderFlag = false;
			},
			sureFun(){
				this.isDisOrderFlag = true;
				if(this.confirmOpt == 'cancel'){
					var field = {orderId:this.currOrderId};
					this.sureBtnTit = '取消中...';
					cancelZxTcOrder(field).then(res=>{
						this.util.showToast('取消成功');
						setTimeout(()=>{
							this.sureBtnTit = '确认';
							this.isDisOrderFlag = false;
							this.currOrderId = '';
							this.initParams();
							this.showAlertFlag = false;
						},1500);
					}).catch(err=>{console.log(err);this.isDisOrderFlag = false;this.sureBtnTit = '确认';});
				}else{//确认再次下单
					let ogzId = uni.getStorageSync('mpOgzId');
					let field = { ogzId,tcId:this.currTcId,jfTag:0 }
					//mixins
					this.addTcOrder(field,'againBuyList','zxTcPayOrder');
					setTimeout(()=>{
						this.cancelDel();
					},300)
				}
			},
			loadTcList(){
				let ogzId = uni.getStorageSync('mpOgzId');
				let { nowPage,orderList } = this;
				this.loading = true;
				var field = { ogzId,opt:1 ,payStatus:this.payStatus,page:this.nowPage,limit:this.limit };
				getZxTcOrderList(field).then(res=>{
					//console.log(res)
					nowPage += 1;
					orderList.push( ...res.data.datas );
					this.orderList = orderList;
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					//console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.orderList = [];
				this.loadTcList();
			},
			switchStatus(payStatus){
				this.payStatus = payStatus;
				this.initParams();
			},
			goPay(item){
				uni.setStorageSync('zxTcInfoField',item);
				this.comJumpOrderPay(item.id,'','zxTcPayOrder');
			},
			goOrderDet(item){
				uni.navigateTo({
					url:'../zxOrderDet/zxOrderDet?orderId=' + item.id + '&currOrderType=zxTcType'
				})
			},
			againBuyZxTc(tcId){
				this.showAlertFlag = true;
				this.confirmOpt = 'againBuy';
				this.alertCon = '是否确认再次购买该咨询套餐?';
				this.currTcId = tcId;
			},
		}
 	}
 </script>
 <style lang='scss'>
 	page{
 		background: $pss-bg-primary;
 		margin-top: 110rpx;
 	}
 </style>
 <style lang="scss" scoped>
 	@import url("/static/css/common/alert.css");
 </style>